<template>
	<view>
		<u-card :title="title" full="true">
			<view class="" slot="body">
				<!--view v-for="item in tableData" :key="item.workid"-->

						<view class="myhomework" v-for="item in dataList" :key="item">
							<view class="courseimg">
								<image :src="item.img" mode="aspectFill"></image>
							</view>
							<view class="" style="margin-left:10px">{{item.courseName}}</view>
							<view class="toright">
								<u-dropdown>
									<u-dropdown-item v-model="value1" title="更多" :options="options1" @change="change(item.courseid)"></u-dropdown-item>
								</u-dropdown>
							</view>
						</view>
				<!--/view-->
			</view>
		</u-card>
	</view>


</template>






<script>
	export default {
		data() {
			return {
				src: 'http://pic2.sc.chinaz.com/Files/pic/pic9/202002/hpic2119_s.jpg',
				title: '我的作业',
				value1: 1,

				options1: [{
						label: '编辑作业',
						value: 1,
					},
					{
						label: '查看成绩',
						value: 2,
					}

				],
				dataList: {},
				tableData: {},
				courseidList: []
			}

		},
		onLoad() {
			this.loadData();
			this.workview();
		},
		methods: {
			change(courseid) {
				console.log("value=" + this.value1);
				if (2 === this.value1) {
					uni.navigateTo({
						url: './homeworkscore?courseid=' + courseid,
					});
				} else if (1 === this.value1) {
					uni.navigateTo({
						url: './work?courseid=' + courseid,
					});
				}
			},
			async loadData() {
				// console.log("1111")
				// console.log("id=" + uni.getStorageSync("stuid"))

				const data = {
					studentid: uni.getStorageSync("stuid")


				}

				let list = await this.$myRequest({
						url: 'api/stucoursed',
						method: 'POST',
						data: data
					})
					.then((res) => {
						console.log(res.data);
						this.dataList = res.data;
					})

				this.dataList = list.data;
				console.log("111");
				console.log("datalist=" + this.dataList);

			},
			async workview() {

				console.log("courseid=" + this.dataList.courseid);
				const data = {
					courseid: uni.getStorageSync("courseid")
				}

				let list = await this.$myRequest({
					url: 'api/stuwork',
					method: 'POST',
					data: data
				})

				//this.dataList = list.data;
				//console.log(list.data);
				

			}

		}
	}
</script>

<style>
	.myhomework{
		display: flex;
		justify-content: space-between;
		margin-bottom: 50rpx;
		
	}
	.courseimg{
		width: 230rpx;
		height: 130rpx;
	}
	.courseimg image{
		width: 100%;
		height: 100%;
	}
	
	.toright {
		margin-left: 50rpx;
	}
</style>
